package edu.nanyang.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import edu.nanyang.dao.StudentInfoDao;
import edu.nanyang.domain.StudentInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class StudentInfoService {
    @Resource
    private StudentInfoDao studentInfoDao;

    /**
     * 分页查询
     *
     * @param page     当前页数
     * @param pageSize 每页个数
     * @return
     */
    public PageInfo<StudentInfo> search(int page, int pageSize) {
        PageHelper.startPage(page, pageSize);//改写语句实现分页查询
        List<StudentInfo> all = studentInfoDao.findAll();
        PageInfo<StudentInfo> info = new PageInfo<>(all);
        return info;
    }

    public StudentInfo getByStudentNumAndPassword(int studentNum, String studentPassword) {
        StudentInfo studentInfo = studentInfoDao.getByStudentNum(studentNum);
        if (null != studentInfo) {
            if (studentInfo.getStudentPassword().equals(studentPassword)) {
                return studentInfo;
            }
        }
        return null;
    }

    public StudentInfo getById(int id) {
        return studentInfoDao.getById(id);
    }

    public int updateClass(int classId, int totalScore, Integer studentNum) {
        return studentInfoDao.updateClass(classId,totalScore,studentNum);
    }

    public List<StudentInfo> findAll(){
        return studentInfoDao.findAll();

    }
   public int add(StudentInfo studentInfo){
        return studentInfoDao.add(studentInfo);
    }
    public int delete(int id){
        return studentInfoDao.delete(id);
    }
    public int update(StudentInfo studentInfo){
        return studentInfoDao.update(studentInfo);
    }

}
